package com.kgc.service.user.impl;

import com.kgc.common.DtoUtil;
import com.kgc.mapper.DmUserMapper;
import com.kgc.pojo.DmUser;
import com.kgc.service.user.DmUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DmUserServiceImpl implements DmUserService {
@Resource
private DmUserMapper dmUserMapper;
    @Override
    public DmUser getDmUserById(Long id) throws Exception {
        return dmUserMapper.getDmUserById(id);
    }

    @Override
    public List<DmUser> getDmUserListByMap(Map<String, Object> param) throws Exception {
        return dmUserMapper.getDmUserListByMap(param);
    }

    @Override
    public Integer getDmUserCountByMap(Map<String, Object> param) throws Exception {
        return dmUserMapper.getDmUserCountByMap(param);
    }

    @Override
    public Integer insertDmUser(DmUser dmUser) throws Exception {
        return dmUserMapper.insertDmUser(dmUser);
    }

    @Override
    public Integer updateDmUser(DmUser dmUser) throws Exception {
        return dmUserMapper.updateDmUser(dmUser);
    }

    @Override
    public Integer deleteDmUserById(Long id) throws Exception {
        return dmUserMapper.deleteDmUserById(id);
    }

    @Override
    public Integer batchDeleteDmUser(Map<String, List<String>> params) {
        return dmUserMapper.batchDeleteDmUser(params);
    }

    @Override
    public boolean chekPhoneOrEmail(String phone) {
        Map<String, Object> map = new HashMap<>();
        map.put("phone", phone);
        try {
            List<DmUser> dmUserListByMap = dmUserMapper.getDmUserListByMap(map);
            if (dmUserListByMap == null || dmUserListByMap.size() == 0) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
